package com.burgeon.backend.SHOP.rest.recharger;
/**
 * 查询余额充值记录 线上单号
 */

import com.burgeon.backend.Rest.base.RESTBase;
import com.burgeon.backend.SHOP.entity.Recharge;
import org.json.JSONArray;
import org.springframework.util.MultiValueMap;

import java.util.ArrayList;
import java.util.HashMap;

public class FindRECHARGEByXSDH extends RESTBase {

    private String ip;
    private String account;
    private String password;

    public FindRECHARGEByXSDH(String ip, String account, String password) {
        this.ip = ip;
        this.account = account;
        this.password = password;
    }

    /**
     * 发送并接收字符创
     * @return
     */

    public Recharge getData(String xsdh) throws Exception {
        String url = "http://"+ip+"/servlets/binserv/Rest";

        String str = RESULT(Data(xsdh),url);
        System.err.println(str);

        String code = new JSONArray(str).getJSONObject(0).getString("code");
        String message = new JSONArray(str).getJSONObject(0).getString("message");
        if (!"0".equals(code)){
            throw new Exception(message);
        }
        JSONArray jsonArray = new JSONArray(str).getJSONObject(0).getJSONArray("rows");


            JSONArray array = jsonArray.getJSONArray(0);
            Recharge recharge = new Recharge();
            recharge.setId(array.getString(0));
            //recharge.setNo(array.getString(1));
            recharge.setStore(array.getString(1));
            recharge.setCreateTime(array.getString(2));
            recharge.setDeposit(array.getString(3));
            recharge.setGive(array.getString(4));
            //recharge.setDiscount(array.getString(6));
            //recharge.setActualsy(array.getString(7));




        return recharge;
    }

    private MultiValueMap Data(String xsdh) {
        HashMap params = new HashMap();
        ArrayList columns = new ArrayList();//查询字段

        columns.add("ID");
       // columns.add("NO");//序号
        columns.add("'C_STORE_ID;NAME'");//店仓
        columns.add("'BILLDATE'");//日期
        columns.add("'TOT_AMT_DEPOSIT'");//充值金额
        columns.add("'TOT_AMT_GIVE'");//赠送金额
        //columns.add("'DISCOUNT'");//折扣
        //columns.add("TOT_AMT_ACTUALSY");//剩余金额
        columns.add("'C_VIP_ID;FA_VIPACC_ID;AMOUNT'");//储值余额

        params.put("columns", columns);
        params.put("table", "YC_VIPMONEY");//表名

        params.put("count","true");



        HashMap paramss = new HashMap();
        String ac = "'"+ xsdh+"'";
        paramss.put("column", "'XSNO'");
        paramss.put("condition", ac);
        params.put("params", paramss);

        return DATA("Query", params,account,password);
    }
    public static void main(String[] args) {
        FindRECHARGEByXSDH getRetailByVip = new FindRECHARGEByXSDH("47.92.53.75:90", "dy@xcx.com", "123");
        try {
            System.err.println(getRetailByVip.getData("123"));

        } catch (Exception e) {
            e.printStackTrace();
        }
    }


}
